import time
import unittest,ddt

from selenium import webdriver
from selenium.webdriver.common.by import By

@ddt.ddt()
class ins(unittest.TestCase):
    def setUp(self) -> None:
        self.wd = webdriver.Chrome()
        self.wd.maximize_window()
        self.wd.get("http://127.0.0.1/mgr/sign.html")
        self.wd.find_element(By.ID, "username").send_keys("byhy")
        self.wd.find_element(By.ID, "password").send_keys(88888888)
        self.wd.find_element(By.XPATH,"/html/body/div/div[2]/div[1]/div[3]/div/button").click()
        time.sleep(2)

    @ddt.file_data("a.json")
    def test_in(self,name,phone,x,y):
        self.wd.find_element(By.XPATH,"//*[@id='root']/div/section[2]/div[1]/button").click()
        self.wd.find_element(By.XPATH,"//*[@id='root']/div/section[2]/div[1]/div[1]/div[1]/input").send_keys(name)
        self.wd.find_element(By.XPATH,"//*[@id='root']/div/section[2]/div[1]/div[1]/div[2]/input").send_keys(phone)
        self.wd.find_element(By.XPATH,"//*[@id='root']/div/section[2]/div[1]/div[2]/button[1]").click()

        if x==0:
            try:
                a = self.wd.switch_to.alert
                a_txt = a.text
                self.assertIn(y,a_txt)
            except AssertionError as A:
                print('断言失败')
                raise A
        if x==1:
            try:
                b=None
                self.assertEqual(y,b)
            except AssertionError as A:
                print('断言失败')
                raise A
    def tearDown(self) -> None:
        self.wd.quit()
if __name__ == '__main__':
    unittest.main()